﻿#ifndef CERRORLOGGER_H__
#define CERRORLOGGER_H__

#include <sstream>
#include <vector>
#include <windows.h>
#include <iosfwd>
#include <fstream>
#include <string>
#include <iomanip>
/*
File: CErrorLogger.h

Leírás:
Loggoló osztály, LOG_INFO, LOG_WARNING, LOG_ERROR makrók használata javasolt a kód naplózása esetén

Szerző:
SevN
*/

namespace Util
{
#define ERRORLOGGER *(CErrorLogger::getErrorLogger())
#define LOG_INFO( str_in ) \
	ERRORLOGGER << "INFO: " <<  str_in << " [ " << __FILE__ << " : " << __LINE__ <<" ]" << "";

#define LOG_WARNING( str_in ) \
	ERRORLOGGER << "WARNING: " <<  str_in << " [ " << __FILE__ << " : " << __LINE__ << " ]" << "";

#define LOG_ERROR( str_in ) \
	ERRORLOGGER << "ERROR: " <<  str_in  << " [ " << __FILE__ << " : " << __LINE__ << " ]" << "";

#define LOG_EXCEPTION( errorStr_in ) \
	ERRORLOGGER << "EXCEPTION: " <<  errorStr_in << "";


class CErrorLogger
{
public:
	static CErrorLogger* getErrorLogger();
	~CErrorLogger();

	template <class T>
	CErrorLogger& operator<<( const T& t_in )
	{	
		std::ostringstream outStream; 
		outStream  <<  t_in;
		strBuffer += outStream.str();
		if (outStream.str() == "")
		{
			commit();
		}
		return *this;
	}
	static void destroy();

private:
	CErrorLogger();

	void initLogFile(const char* fname);

	void commit();

	std::ofstream logFile;
	std::string strBuffer;  

	static CErrorLogger* errorLogger;
protected:


};
}//namespace Util


#endif